<template>
  <div class="photo-box">
    <div class="cagegory-box">
      <ul class="cagegory">
        <li v-for="item in cagegoryList" :key="item.id" @click="getPhotoListByCateId(item.id)">
          <mt-button type="default" size="small">{{item.title}}</mt-button>
        </li>
      </ul>
    </div>
    <ul class="photo-list">
      <router-link :to="'/home/photoinfo/'+item.id" v-for="item in imglist" :key="item.id" tag="li">
        <img v-lazy.container="item.img_url">
        <div class="info">
          <h1 class="info-title">{{ item.title }}</h1>
          <div class="info-body">{{ item.zhaiyao }}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      cagegoryList: [],
      imglist: [],
      cateid: "0"
    };
  },
  created() {
    this.getcagegoryList();
    this.getimages(0);
  },
  methods: {
    getcagegoryList() {
      this.$http.get("api/getimgcategory").then(result => {
        if (result.body.status == 0) {
          result.body.message.forEach(item => {
            this.cagegoryList.push(item);
          });
        } else {
          Toast("获取失败");
          return;
        }
      });
    },
    getPhotoListByCateId(id) {
      console.log(id);
      this.cateid = id;
      this.getimages(id);
    },
    getimages(id) {
      this.$http.get("api/getimages/" + id).then(result => {
        if (result.body.status == 0) {
          this.imglist = [];
          result.body.message.forEach(item => {
            this.imglist.push(item);
          });
        } else {
          Toast("获取失败");
          return;
        }
      });
    }
  }
};
</script>

<style lang="scss" scope>
.cagegory-box {
  width: 100%;
  overflow: hidden;
  li {
    float: left;
  }
}
.photo-list {
  list-style: none;
  margin: 0;
  padding: 10px;
  padding-bottom: 0;
  li {
    background-color: #ccc;
    text-align: center;
    margin-bottom: 10px;
    box-shadow: 0 0 9px #999;
    position: relative;
    img {
      width: 100%;
      vertical-align: middle;
    }
    img[lazy="loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
    }

    .info {
      color: white;
      text-align: left;
      position: absolute;
      bottom: 0;
      background-color: rgba(0, 0, 0, 0.4);
      max-height: 84px;
      .info-title {
        font-size: 14px;
      }
      .info-body {
        font-size: 13px;
      }
    }
  }
}
</style>